const { TAGNAME_REQUIRED } = require('../constants/error-types');
const CustomError = require('../utils/error');

const validateName = async (ctx, next) => {
  const { name = '' } = ctx.request.body;
  if (!name) {
    const err = new CustomError(TAGNAME_REQUIRED);
    return ctx.app.emit('error', err, ctx);
  }
  await next();
};

module.exports = { validateName };
